package com.iot08.api.controller;

import com.iot08.api.controller.base.BaseController;
import com.iot08.api.service.ActiveUserService;
import com.iot08.api.service.AdvertUserService;
import com.iot08.api.service.VisitHistoryService;
import com.iot08.api.vo.request.AddAdvertUserReqVO;
import com.iot08.api.vo.request.AddVisitHistoryReqVO;
import com.iot08.common.utils.StringUtil;
import com.iot08.common.utils.response.ResponseMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Description: 用户信息采集业务
 * @time: 2020/12/21 17:46
 * @author: Rock
 */
@RestController
@RequestMapping("getway/infoCollect")
public class InfoCollectController extends BaseController {

    @Resource
    private ActiveUserService activeUserService;
    @Resource
    private AdvertUserService advertUserService;
    @Resource
    private VisitHistoryService visitHistoryService;

    /**
     * 媒体位用户点击
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/21 18:48
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("advertUser")
    public ResponseMap advertUser(@Validated AddAdvertUserReqVO vo, BindingResult bindingResult) {
        advertUserService.add(vo);
        return ResponseMap.success();
    }

    /**
     * 用户信息数据采集
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/22 10:49
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("visitHistory")
    public ResponseMap visitHistory(@Validated AddVisitHistoryReqVO vo, BindingResult bindingResult) {
        String openid = vo.getOpenid();
        if (StringUtil.isNotBlank(openid)) {
            //用户信息采集
            visitHistoryService.add(vo);
            //活跃用户采集
            activeUserService.add(vo, this.getVersion());
        }
        return ResponseMap.success();
    }

}
